package com.sesame.controller;

import com.sesame.defin.AbstractController;
import com.sesame.defin.Response;
import com.sesame.entity.User;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.MessageFormat;

@CommonsLog
@RestController
@RequestMapping("/test")
public class TestController extends AbstractController {

    @Autowired
    Environment environment;

    /**
     * http://localhost:8081/test/index?name=1&pwd=aaa
     */
    @RequestMapping("/index")
    public ApiResult index(String name, String pwd) {
        System.out.println("service run .... ");
        String logstr = MessageFormat.format("name={0},pwd={1}", name, pwd);
        log.info(">>>>> : " + logstr);

        User user = new User();
        user.setName(name);
        user.setPwd(pwd);
        user.setPort(environment.getProperty("spring.cloud.nacos.discovery.ip") + ":" + environment.getProperty("server.port"));

        return success(user);
    }


}
